﻿using YiJingFramework.Core;
using YiJingFramework.Painting.Deriving.Extensions;
using YiJingFramework.Painting.Presenting;
using YiJingFramework.References.Zhouyi;

var converter = new CharacterConverter();
var zhouyi = new Zhouyi("translation.json");

var trigrams = new Painting[]
{
    Painting.FromBytes(0b1_111),
    Painting.FromBytes(0b1_001),
    Painting.FromBytes(0b1_010),
    Painting.FromBytes(0b1_100),
    Painting.FromBytes(0b1_000),
    Painting.FromBytes(0b1_110),
    Painting.FromBytes(0b1_101),
    Painting.FromBytes(0b1_011)
};

var paddingChar = '　';
Console.OutputEncoding = System.Text.Encoding.UTF8;

foreach(var trigramPainting in trigrams)
{
    Console.WriteLine($"{zhouyi.GetTrigram(trigramPainting).Name}" +
        $"{converter.ConvertTo(trigramPainting)}宫：");

    var hexagramPainting = new Painting(trigramPainting.Concat(trigramPainting));
    Console.Write($"本卦" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(0);
    Console.Write($"一世" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(1);
    Console.Write($"二世" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(2);
    Console.Write($"三世" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(3);
    Console.Write($"四世" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(4);
    Console.Write($"五世" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(3);
    Console.Write($"游魂" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}"
        .PadRight(4, paddingChar));

    hexagramPainting = hexagramPainting.ChangeLines(0, 1, 2);
    Console.Write($"归魂" +
        $"{zhouyi.GetHexagram(hexagramPainting).Name}{converter.ConvertTo(hexagramPainting)}");

    Console.WriteLine();
    Console.WriteLine();
}
